package com.mall.shop.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mall.shop.constants.PageConstrant;
import com.mall.shop.mapper.BrandMapper;
import com.mall.shop.entity.product.Brand;
import com.mall.shop.service.BrandService;
import com.mall.shop.utils.Query;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.Map;

/**
 * 品牌(Brand)表服务实现类
 *
 * @author 龙茶清欢
 * @since 2023-01-16 15:32:39
 */
@Service("brandService")
public class BrandServiceImpl extends ServiceImpl<BrandMapper, Brand> implements BrandService {

    @Override
    public IPage<Brand> findBrandByPage(Map<String, Object> params) {
        IPage<Brand> page = new Query<Brand>().getPage(params);

        LambdaQueryWrapper<Brand> queryWrapper = new LambdaQueryWrapper<>();
        String queryKey = (String) params.get(PageConstrant.QUERY_KEY);
        if (StringUtils.isNotBlank(queryKey)) {
            queryWrapper.eq(Brand::getBrandId, queryKey).or().like(Brand::getName, queryKey);
        }

        return this.baseMapper.selectPage(page, queryWrapper);
    }
}

